import javax.swing.*;

public class RegisterView extends JFrame{
    public RegisterView() {
        JLabel l_title = new JLabel("注册页面");
        JLabel l_username=new JLabel("用户名");
        JLabel l_password=new JLabel("密码");
        JLabel l_password2=new JLabel("请再次输入密码");
        JTextField t_username=new JTextField();
        JTextField t_password=new JPasswordField();
        JTextField t_password2=new JPasswordField();
        JButton reset=new JButton("清空");
        JButton login=new JButton("注册");
        JPanel panel=new JPanel();
        panel.setLayout(null);
        l_title.setBounds(150, 20, 100, 50);
        l_username.setBounds(100, 80, 100, 20);
        l_password.setBounds(100, 120, 100, 20);
        l_password2.setBounds(50, 160, 100, 20);
        t_username.setBounds(150, 80, 120, 20);
        t_password.setBounds(150, 120, 120, 20);
        t_password2.setBounds(150, 160, 120, 20);
        reset.setBounds(130, 200, 60, 20);
        login.setBounds(200, 200, 60, 20);
        reset.addActionListener(e -> {
            t_username.setText("");
            t_password.setText("");
            t_password2.setText("");
        });

        login.addActionListener(e -> {
            String username=t_username.getText();
            String password=t_password.getText();
            String password2=t_password2.getText();
            if(username.equals("") || password.equals("") || password2.equals("")) {
                JOptionPane.showMessageDialog(null, "请填写完整内容", "注册失败", JOptionPane.WARNING_MESSAGE);
            } else if(!password.equals(password2)) {
                JOptionPane.showMessageDialog(null, "两次密码输入不一致", "注册失败", JOptionPane.WARNING_MESSAGE);
            }else  {
                JOptionPane.showMessageDialog(null, "注册成功", "注册成功", JOptionPane.INFORMATION_MESSAGE);
            }
        });
        panel.add(l_password2);
        panel.add(t_password2);
        panel.add(l_title);
        panel.add(l_username);
        panel.add(l_password);
        panel.add(t_username);
        panel.add(t_password);
        panel.add(reset);
        panel.add(login);
        this.add(panel);
        this.setTitle("注册页面");
        this.setSize(400,300);
        this.setVisible(true);
        this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    }
    public static void main(String[] args) {
        new RegisterView();
    }
}
